﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using UnityScriptEngine;


namespace MBB_Payroll_Terminal
{
    public partial class frmSettings : Form
    {
        public static object[] setPref = new object[0];
        public frmSettings()
        {
            InitializeComponent();
            InitializeFrameSliderForm();
        }
        private void InitializeForm()
        {
            btnSave.Click += new EventHandler(btnSave_Click);

            //Load Settings
            LoadSettings();
            try
            {
                txtServer.Text = UnityProcessor.Settings.DBPU_Server;
                txtDatabase.Text = UnityProcessor.Settings.DBPU_Database;
                txtUID.Text = UnityProcessor.Settings.DBPU_UID;
                txtPWD.Text = UnityProcessor.Settings.DBPU_PWD;
                chkDebugMode.Checked = bool.Parse(setPref[0].ToString());
                chkFullScreen.Checked = bool.Parse(setPref[1].ToString());
            }
            catch (Exception ex)
            {
            }
        }

        void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtUID.Text.Equals(txtPWD.Text))
                {
                    UnityProcessor.Settings.APP_ID = "MBB Payroll Terminal";
                    UnityProcessor.Settings.APP_Name = "MBB Payroll Terminal";
                    UnityProcessor.Settings.DBPU_Server = txtServer.Text;
                    UnityProcessor.Settings.DBPU_Database = txtDatabase.Text;
                    UnityProcessor.Settings.DBPU_UID = txtUID.Text;
                    UnityProcessor.Settings.DBPU_PWD = txtPWD.Text;
                    UnityProcessor.Settings.RFFPU_Server = " ";
                    UnityProcessor.Settings.RFFPU_UID = " ";
                    UnityProcessor.Settings.RFFPU_PWD = " ";
                    UnityProcessor.SettingsWrite();
                    object[] setPref = new object[] { chkDebugMode.Checked.ToString(), chkFullScreen.Checked.ToString() };
                    UnityProcessor.SettingsWritePreferences(setPref);

                    PanelForm.Dispose();
                }
                else
                {
                    MessageBox.Show("Password does not match!", "Settings", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Settings", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public static void LoadSettings()
        {
            try
            {
                UnityProcessor.SettingsRead("MBB Payroll Terminal");
                setPref = UnityProcessor.SettingsReadPreferences("MBB Payroll Terminal");
            }
            catch (Exception ex)
            {
            }
        }
    }
}
